<?
include_once 'library.php';
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<title>SK Communications A11Y Score Board</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- Bootstarap Version -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.css" />
<!-- //Bootstarap Version -->
<script type="text/javascript" src="js/common.js"></script>
<!-- Basic Style -->
<link type="text/css" rel="stylesheet" href="css/style.css" />
<!-- //Basic Style -->
</head>
<body>
<?
$table_name = "service_url";
$nate_total_count = 0;
$nate_total_avg = 0;
$cy_total_count = 0;
$cy_total_avg = 0;
$select_array = array("*");
$url_nate = array();
$url_cyworld = array();
$service_url = selectDB($table_name, $select_array, "flag = '1'");

/* URL Categoriging */
for($i=0; $i<count($service_url); $i++){
	if($service_url[$i]['category'] == 'n'){
		array_push($url_nate, $service_url[$i]);
	}else{
		array_push($url_cyworld, $service_url[$i]);
	}
}

/* Categorized URL Array Sort By Rank Column */
usort($url_nate, "cmp");
usort($url_cyworld, "cmp");

function cmp($a, $b) 
{
  if ($a["rank"] == $b["rank"]) {
      return 0;
  }
  return ($a["rank"] > $b["rank"]) ? 1 : -1;

}


for($i=0; $i<count($url_nate);$i++){
	$title = $url_nate[$i]['title'];
	$url = $url_nate[$i]['url'];
	$result = avgURL($url);
	$score = $result[0];
	$count = $result[1];
	
	if($score >= 95){
		$className = "progress-success";
	}else if($score >= 70){
		$className = "progress-warning";
	}else{
		$className = "progress-danger";
	}
	
	$print_item_nate = $print_item_nate."
		<li>
			<div class=\"progress progress-vertical $className\" title=\"$count 건\">
				<div class=\"bar\" style=\"height: $score%\"><span class=\"score\">$score</span></div>
			</div>
			<p><a href=\"$url\" target=\"_blank\">$title</a></p>
		</li>
	";	
	
	$nate_total_count = $nate_total_count + $count;
	$nate_score = $nate_score + $score;
}

for($i=0; $i<count($url_cyworld);$i++){
	$title = $url_cyworld[$i]['title'];
	$url = $url_cyworld[$i]['url'];
	$result = avgURL($url);
	$score = $result[0];
	$count = $result[1];
	
	if($score >= 95){
		$className = "progress-success";
	}else if($score >= 70){
		$className = "progress-warning";
	}else{
		$className = "progress-danger";
	}
	
	$print_item_cyworld = $print_item_cyworld."
		<li>
			<div class=\"progress progress-vertical $className\" title=\"$count 건\">
				<div class=\"bar\" style=\"height: $score%\"><span class=\"score\">$score</span></div>
			</div>
			<p><a href=\"$url\" target=\"_blank\">$title</a></p>
		</li>
	";	
	
	$cyworld_total_count = $cyworld_total_count + $count;
	$cyworld_score = $cyworld_score + $score;
}

$nate_total_avg = number_format(($nate_score / count($url_nate)), 2);
$cyworld_total_avg = number_format(($cyworld_score / count($url_cyworld)), 2);

$comms_total_count = $nate_total_count+$cyworld_total_count;
$comms_total_avg = ($nate_total_avg + $cyworld_total_avg) / 2;

/* Average to URL Function(Recently Check Data not include overlap) */
function avgURL($url){
	$table_name = "test_result";
	$search_condition = "url LIKE '$url%'";
	$condition = "$search_condition ORDER BY timestamp desc";
	$totalCount = count(selectDBQ("SELECT * FROM (SELECT * FROM $table_name WHERE $condition ) AS pseudoTable GROUP BY pseudoTable.url ORDER BY pseudoTable.timestamp DESC"));
	$score_sum = selectDBQ("SELECT SUM(scoreTable.score) FROM (SELECT * FROM (SELECT * FROM $table_name WHERE $condition ) AS pseudoTable GROUP BY pseudoTable.url ORDER BY pseudoTable.timestamp DESC) AS scoreTable");
	$avg = number_format($score_sum[0][0] / $totalCount,2);
	$result = array($avg, $totalCount);
	return $result;
}


?>
<div id="wrap">
	<div class="contents">
		<div class="navWrap">
			<h3>SK Communications A11Y</h2></h3>
			<div class="navbar">
				<div class="navbar-inner">
					<div class="container">
						<ul class="nav">
							<li><a href="/tools/a11y/">홈</a></li>
							<li><a href="/tools/a11y/install.html">설치 가이드 &amp; 다운로드</a></li>
							<li><a href="/tools/a11y/score_check.php">점수 집계표</a></li>
							<li class="active"><a href="/tools/a11y/service.php">서비스별 평균 점수표</a></li>
							<li><a href="/tools/a11y/rank.php">사내 측정 횟수표</a></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<ul class="nav nav-tabs" id="serviceTab">
			<li><a href="#nate" data-toggle="tab"><img src="img/tab_nate.png" alt="NATE" /></a></li>
			<li><a href="#cyworld" data-toggle="tab"><img src="img/tab_cyworld.png" alt="CYWORLD" /></a></li>
		</ul> 		
		<div class="tab-content">
			<div class="tab-pane active" id="nate">
				<div class="stat-container">
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=number_format($nate_total_count)?></span>
							네이트 전체 건수
						</div>
					</div>
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=$nate_total_avg?></span>
							네이트 전체 평균
						</div>
					</div>
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=number_format($comms_total_count)?></span>
							N+C 전체 건수
						</div>
					</div>
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=$comms_total_avg?></span>							
							N+C 전체 평균	
						</div>
					</div>
				</div>
				<div class="chart_header">
					<i class="icon-signal"></i><h3>Bar Chart</h3>
				</div>
				<div class="chart">
					<div class="wrap">
						<ul>
						<?=$print_item_nate?>
						</ul>
					</div>
				</div>
			</div>
						
			<div class="tab-pane" id="cyworld">
				<div class="stat-container">
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=number_format($cyworld_total_count)?></span>
							싸이월드 전체 건수
						</div>
					</div>
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=$cyworld_total_avg?></span>
							싸이월드 전체 평균
						</div>
					</div>
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=number_format($comms_total_count)?></span>
							N+C 전체 건수
						</div>
					</div>
					<div class="stat-holder">						
						<div class="stat">							
							<span><?=$comms_total_avg?></span>							
							N+C 전체 평균	
						</div>
					</div>
				</div>
				<div class="chart_header">
					<i class="icon-signal"></i><h3>Bar Chart</h3>
				</div>
				<div class="chart">
					<div class="wrap">
						<ul>
						<?=$print_item_cyworld?>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<br/>
		<ul>
			<li><i class="icon icon-ok"></i> &nbsp; 막대그래프 위에 마우스를 올리면 서비스별 측정 건수가 표시됩니다.</li>
			<li><i class="icon icon-ok"></i> &nbsp; 측정 점수 및 평균 점수는 접근성 확보의 절대적 판단기준이 되지 않습니다.</li>
		</ul>
	<div>
</div>
<div class="footer">2013. SK Communications | UI Dev Team</div>
<script type="text/javascript">
	$('#serviceTab a').click(function (e) {
		e.preventDefault();
		$(this).tab('show');
})

	$('#serviceTab a:first').tab('show');
</script>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-39065309-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>
</html>
